package com.erp.wallet.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.wallet.domain.bo.ErpSellerStoreWalletOrderBo;
import com.erp.wallet.domain.vo.ErpSellerStoreWalletOrderVo;
import com.erp.wallet.service.IErpSellerStoreWalletOrderService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.pay.AlipayConfig;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 钱包订单
 *
 * @author erp
 * @date 2023-05-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreWalletOrder")
public class ErpSellerStoreWalletOrderController extends BaseController {

    private final IErpSellerStoreWalletOrderService iErpSellerStoreWalletOrderService;
    
    @Autowired
    AlipayConfig alipayConfig;
    /**
     * 查询钱包订单列表
     */
    @SaCheckPermission("seller:sellerStoreWalletOrder:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreWalletOrderVo> list(ErpSellerStoreWalletOrderBo bo, PageQuery pageQuery) {
        return iErpSellerStoreWalletOrderService.queryPageList(bo, pageQuery);
    }
    @GetMapping("/getInfo")
    public String getInfo() {
        
        return alipayConfig.getAppId() + alipayConfig.getPrivateKey();
    }

    /**
     * 
     * 导出钱包订单列表
     */
    @SaCheckPermission("seller:sellerStoreWalletOrder:export")
    @Log(title = "钱包订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpSellerStoreWalletOrderBo bo, HttpServletResponse response) {
        List<ErpSellerStoreWalletOrderVo> list = iErpSellerStoreWalletOrderService.queryList(bo);
        ExcelUtil<ErpSellerStoreWalletOrderVo> excelUtil = new ExcelUtil<>(ErpSellerStoreWalletOrderVo.class);
        excelUtil.exportExcel(response,list,"钱包订单");
    }

    /**
     * 获取钱包订单详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:sellerStoreWalletOrder:query")
    @GetMapping("/{id}")
    public R<ErpSellerStoreWalletOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStoreWalletOrderService.queryById(id));
    }

    /**
     * 新增钱包订单
     */
    @PostMapping()
    public R<Object> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreWalletOrderBo bo) {
        return iErpSellerStoreWalletOrderService.insertByBo(bo);
    }

    /**
     * 修改钱包订单
     */
    @SaCheckPermission("seller:sellerStoreWalletOrder:edit")
    @Log(title = "钱包订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreWalletOrderBo bo) {
        return toAjax(iErpSellerStoreWalletOrderService.updateByBo(bo));
    }

    /**
     * 删除钱包订单
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:sellerStoreWalletOrder:remove")
    @Log(title = "钱包订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreWalletOrderService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
